package com.example.review.Fragment;


import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ActionMenuView;
import android.widget.Button;
import android.widget.Toast;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.example.review.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class IntentFragment extends Fragment {

    @BindView(R.id.Ibutton1)
    Button Ibutton1;
    @BindView(R.id.Ibutton2)
    Button Ibutton2;
    @BindView(R.id.Ibutton3)
    Button Ibutton3;
    @BindView(R.id.Ibutton4)
    Button Ibutton4;
    @BindView(R.id.Ibutton5)
    Button Ibutton5;
    @BindView(R.id.Ibutton6)
    Button Ibutton6;
    @BindView(R.id.Ibutton7)
    Button Ibutton7;
    private View view;

    public IntentFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_intent, container, false);
        ButterKnife.bind(this,view);
        int i = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CALL_PHONE);
        if(i != PackageManager.PERMISSION_GRANTED) {
            //弹出对话框
            ActivityCompat.requestPermissions(getActivity(),new String[]{Manifest.permission.CALL_PHONE},1);
        }
        return view;
    }

    @OnClick({R.id.Ibutton1, R.id.Ibutton2, R.id.Ibutton3, R.id.Ibutton4, R.id.Ibutton5, R.id.Ibutton6, R.id.Ibutton7})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.Ibutton1:
                //拨号
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:"+13973356624L));
                startActivity(intent);
                break;
            case R.id.Ibutton2:
                //设置
                startActivity(new Intent(Settings.ACTION_SETTINGS));
                break;
            case R.id.Ibutton3:
                //时间
                startActivity(new Intent(Settings.ACTION_DATE_SETTINGS));
                break;
            case R.id.Ibutton4:
                //网络
                startActivity(new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS));
                break;
            case R.id.Ibutton5:
                //蓝牙
                startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));
                break;
            case R.id.Ibutton6:
                //位置服务
                startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                break;
            case R.id.Ibutton7:
                //wifi
                startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                break;
        }
    }
}
